<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>迭代器</title>
</head>
<body>
    <script>
        let arr=['a','b','c','d'];
        // 返回迭代器对象 ()在[]外
        let it =arr[Symbol.iterator](); //为迭代器方法
        console.log(it);
        // 迭代器的方法 .next() 为选择迭代器对象中的下一条数据
            // console.log(it.next().value);
            // console.log(it.next().value);
            // console.log(it.next().value);
            // console.log(it.next().value);
            /* 返回值为对象 键为done：ture/false  值为value  */
            // console.log(it.next());


        let obj = it.next();
        while(!obj.done){
            console.log(obj.value);
            // 防止陷入死循环
            obj = it.next();
        }
        
        
    </script>
</body>
</html>